package game.level;

import engine.game.Level;
import engine.game.Manager;
import engine.graphics.Vertex2f;
import engine.input.IInput;
import engine.objects.GameObjects;
import engine.objects.PhysicsObject;
import engine.system.EDirection;
import game.objects.nonstaticObjects.* ; 

import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;

public class EntityManager extends Manager implements IInput{
	
	private static final long serialVersionUID = 1L;
		
	private PlayerModel player ; 
	private SkeletonModel skeleton ; 
	
	public EntityManager(GameObjects go, Level lvl){
		super(go, lvl);
		init();
	}

	@Override
	public void init() {
		super.init(); 
		
		player = new PlayerModel(this, 150, 300); 
		skeleton = new SkeletonModel(this, 300, 300); 
		this.addNewObject(player); 
		this.addNewObject(skeleton);
	}
	
	public void createNewFigure(){
		
	}

	public EntityModel getPlayer(){
		return player ; 
	}
	
	public void render(){
		super.render() ; 
	}

	public void remove(PhysicsObject o){
		if(o == player)
			this.getLevel().getGame().exit();
		else
			super.remove(o);
	}
	
	@Override
	public void getInput() {
		if (Keyboard.isKeyDown(Keyboard.KEY_SPACE))
			player.enableJumping(); 				
		if(Keyboard.isKeyDown(Keyboard.KEY_D))
			player.move(EDirection.RIGHT); 
		if(Keyboard.isKeyDown(Keyboard.KEY_A))
			player.move(EDirection.LEFT);  
//		if(Keyboard.isKeyDown(Keyboard.KEY_S))
//			player.enableCrouching(); 
		if(Mouse.next()){
			if(Mouse.getEventButtonState()){
				if(Mouse.getEventButton() == 0){
					player.shootRope(new Vertex2f(Mouse.getX(), Mouse.getY())); 
				}
				else if(Mouse.getEventButton() == 1)
						player.releaseRope();
			}
		}
	}
	
}
